package nero.yncc.com.createart.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import java.util.List;

import nero.yncc.com.createart.R;
import nero.yncc.com.createart.bean.BeanCategory;
import nero.yncc.com.createart.bean.CategoryLeftBean;

/**
 * Created by Administrator.
 * Time:2017/3/10 11:10.
 */

public class AdapterCategoryLeftBox extends BaseAdapter {

    private List<BeanCategory> leftList;
    private Context context;
    private int index = -1;

    public AdapterCategoryLeftBox(List<BeanCategory> leftList, Context context) {
        this.leftList = leftList;
        this.context = context;
    }

    public void setSelectIndex(int index) {
        this.index = index;
    }

    @Override
    public int getCount() {
        return leftList.size();
    }

    @Override
    public Object getItem(int i) {
        return leftList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View convertView, ViewGroup viewGroup) {
        Holder holder;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.adapter_category_left, null);
            holder=new Holder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        holder.tvLeft.setText(leftList.get(i).getName());
        /** 选中的行: 黄色, 否则白色  */
        if(index == i){
            convertView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.border_left_yellow));
            holder.tvLeft.setTextColor(context.getResources().getColor(R.color.project_yellow));
        }else{
            convertView.setBackgroundColor(context.getResources().getColor(R.color.white));
            holder.tvLeft.setTextColor(context.getResources().getColor(R.color.textColorGray_deep));
        }


        return convertView;
    }

    class Holder {
        private TextView tvLeft;
        public  Holder(View root){
            tvLeft=root.findViewById(R.id.tv_content);
        }
    }
}
